<?php

namespace App\Http\Controllers\Admin;

use App\AdminModel;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class AdminController extends Controller
{

    public function index()
    {
        return view("admin.index");
    }


    public function page()
    {
        return view("admin.page");
    }


    public function base()
    {
        return view("admin.base");
    }


    public function types()
    {
        return view("admin.types");
    }

    public function add()
    {
        return view("admin.addtype");
    }

    public function addinfo(Request $request)
    {
        $data = $request->input();
        $id=$data["id"];

        if ($id==0) {
            $ok = AdminModel::create($data);
            return "添加成功
            <a href='add'><button>添加数据</button></a>
            <a href='korux'><button>查看数据</button></a>";
        } else {
           $ok=AdminModel::where("id",$id)->first();
           $ok->update($data);
            return "修改成功
             <a href='add'><button>添加数据</button></a>
             <a href='korux'><button>查看数据</button></a>";
        }
    }


    public function korux()
    {
        $data=AdminModel::get();
        return view("admin.types" ,compact("data"));
    }




    public function update(Request $request)
    {
        $id=$request->input('id');
        $ok=AdminModel::where('id',$id)->first();
        return view("admin.addtype",compact("ok"));
}

    public function delete(Request $request)
    {
        $data = $request->input();
        $id=$data["id"];
        $ok=AdminModel::where("id",$id)->first();
       $del=$ok->delete($data);
       if ($del){
           return view("admin.types");
       }else{
           return view("admin.types");
       }
}


}
